#!C:/strawberry/perl/bin/perl.exe

use strict;
use warnings;

use CGI qw(:standard);
use RPC::XML;
use RPC::XML::Client;
#use XML::Dumper;
use Data::Dumper;
use XML::Simple;
use XML::eXistDB::RPC;
use XML::Compile::RPC::Client;

# read the CGI params
my $cgi = CGI->new;
my $correo = $cgi->param("correo");
my $eXist = XML::eXistDB::RPC->new(destination=>"http://localhost:8080/exist/xmlrpc/", repository=>"/db", user=>"admin", password=>"eaf2julian" ) ;

my $xquery = 'doc("/placeanddate/usuarios.xml")/usuarios/usuario/email[text() eq "'.$correo.'"]' ;
my ($rc1, $set) = $eXist->executeQuery($xquery) ;
my ($rc2, $count) = $eXist->numberOfResults($set) ;
#print Dumper($count) ;
my ($rc3, @data) = $eXist->retrieveResults($set) ;
#$eXist->releaseResultSet($set) ;
#print Dumper(@data) ;


#my $maildevuelto = $data[0]{'email'};
#my $hits = $data[0]{'hitCount'};

# create a JSON string according to the database result
my $json =qq{{"hits" : "$count","correo":"$correo"}};
# return JSON string
print $cgi->header(-type => "application/json", -charset => "utf-8");
print $json;